{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "pandas是基于Numpy构建的，这让以Numpy为中心的应用变得更加简单。  \n",
    "pandas主要包括三类数据结构，分别是：  \n",
    "\n",
    "Series：一维数组，与Numpy中的一维数组类似。二者与Python基本的数据结构List也很相近，其区别是：  \n",
    "List中的元素可以是不同的数据，而Array和Series中则只允许存储相同的数据类型，这样可以更有效地使用内存，提高运算效率。  \n",
    "\n",
    "DataFrame：二维的表格型数据结构。很多功能与R中的data.frame类似。可以将DataFrame理解为Series的容器。以下的内容主要以DataFrame为主。  \n",
    "\n",
    "Panel：三维的数组，可以理解为DataFrame的容器。 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Series(一维数组)\n",
    "由一维数据（各种Numpy类型数据），以及一组与之相关的标签数据（即索引）组成。  \n",
    "仅由一组数据即可产生最简单的Series，可以通过传递一个**列表**对象来创建一个Series."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1.0\n",
       "1    3.0\n",
       "2    5.0\n",
       "3    NaN\n",
       "4    6.0\n",
       "5    8.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "s1 = pd.Series([1,3,5,np.nan,6,8])\n",
    "s1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=6, step=1)"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 获取Series的索引\n",
    "s1.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1.,  3.,  5., nan,  6.,  8.])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看Series的值\n",
    "s1.values"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# DataFrame(二维的表格型数据结构)\n",
    "DataFrame是一个表格型数据结构，它含有一组有序的列，每一列的数据类型都是相同的，而不同的列之间的数据类型可以不同。  \n",
    "DataFrame即有行索引也有列索引，可以被看作是由Series组成的字典（共用同一个索引）。\n",
    "\n",
    "## 通过传递list对象来创建DataFrame\n",
    "该DataFrame包括一个Numpy array,时间索引和列名："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2019-06-01', '2019-06-02', '2019-06-03', '2019-06-04',\n",
       "               '2019-06-05', '2019-06-06', '2019-06-07', '2019-06-08',\n",
       "               '2019-06-09', '2019-06-10'],\n",
       "              dtype='datetime64[ns]', freq='D')"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "# 创建index索引\n",
    "dates = pd.date_range('20190601', periods=10)\n",
    "dates"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "dtype('<M8[ns]')"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dates.dtype"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2.69297768, 3.72536811, 8.10431772, 7.66789474],\n",
       "       [1.46074562, 7.67581026, 5.01516519, 4.94695913],\n",
       "       [6.63719305, 7.48005877, 3.7098792 , 5.80306261],\n",
       "       [8.07875205, 4.24705293, 7.10631097, 8.17703498],\n",
       "       [3.11648887, 4.0553481 , 2.7628006 , 9.01624163],\n",
       "       [8.78071274, 0.38166534, 0.69562703, 8.47723792],\n",
       "       [1.94436804, 0.13961663, 8.14169589, 3.36878086],\n",
       "       [1.01447731, 6.48016637, 8.08521017, 5.16708714],\n",
       "       [9.26159509, 4.1619483 , 8.54252036, 4.26771678],\n",
       "       [6.51615677, 7.82462781, 6.79719634, 3.13209308]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "rand_data = np.random.rand(10,4)*10 # 10行4列\n",
    "rand_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>2.692978</td>\n",
       "      <td>3.725368</td>\n",
       "      <td>8.104318</td>\n",
       "      <td>7.667895</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>1.460746</td>\n",
       "      <td>7.675810</td>\n",
       "      <td>5.015165</td>\n",
       "      <td>4.946959</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>6.637193</td>\n",
       "      <td>7.480059</td>\n",
       "      <td>3.709879</td>\n",
       "      <td>5.803063</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>8.078752</td>\n",
       "      <td>4.247053</td>\n",
       "      <td>7.106311</td>\n",
       "      <td>8.177035</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>3.116489</td>\n",
       "      <td>4.055348</td>\n",
       "      <td>2.762801</td>\n",
       "      <td>9.016242</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>8.780713</td>\n",
       "      <td>0.381665</td>\n",
       "      <td>0.695627</td>\n",
       "      <td>8.477238</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>1.944368</td>\n",
       "      <td>0.139617</td>\n",
       "      <td>8.141696</td>\n",
       "      <td>3.368781</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>1.014477</td>\n",
       "      <td>6.480166</td>\n",
       "      <td>8.085210</td>\n",
       "      <td>5.167087</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>9.261595</td>\n",
       "      <td>4.161948</td>\n",
       "      <td>8.542520</td>\n",
       "      <td>4.267717</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>6.516157</td>\n",
       "      <td>7.824628</td>\n",
       "      <td>6.797196</td>\n",
       "      <td>3.132093</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  2.692978  3.725368  8.104318  7.667895\n",
       "2019-06-02  1.460746  7.675810  5.015165  4.946959\n",
       "2019-06-03  6.637193  7.480059  3.709879  5.803063\n",
       "2019-06-04  8.078752  4.247053  7.106311  8.177035\n",
       "2019-06-05  3.116489  4.055348  2.762801  9.016242\n",
       "2019-06-06  8.780713  0.381665  0.695627  8.477238\n",
       "2019-06-07  1.944368  0.139617  8.141696  3.368781\n",
       "2019-06-08  1.014477  6.480166  8.085210  5.167087\n",
       "2019-06-09  9.261595  4.161948  8.542520  4.267717\n",
       "2019-06-10  6.516157  7.824628  6.797196  3.132093"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 创建columns索引\n",
    "list = ['open','high','low','close']\n",
    "df21 = pd.DataFrame(rand_data, index=dates, columns=list)\n",
    "df21"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 通过传递dict对象来创建DataFrame:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>A</th>\n",
       "      <th>B</th>\n",
       "      <th>C</th>\n",
       "      <th>D</th>\n",
       "      <th>E</th>\n",
       "      <th>F</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.0</td>\n",
       "      <td>2013-01-01</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "      <td>test</td>\n",
       "      <td>foo</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>1.0</td>\n",
       "      <td>2013-01-01</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "      <td>train</td>\n",
       "      <td>foo</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1.0</td>\n",
       "      <td>2013-01-01</td>\n",
       "      <td>1.0</td>\n",
       "      <td>3</td>\n",
       "      <td>test</td>\n",
       "      <td>foo</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1.0</td>\n",
       "      <td>2013-01-01</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2</td>\n",
       "      <td>train</td>\n",
       "      <td>foo</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     A          B    C  D      E    F\n",
       "4  1.0 2013-01-01  1.0  3   test  foo\n",
       "5  1.0 2013-01-01  1.0  2  train  foo\n",
       "6  1.0 2013-01-01  1.0  3   test  foo\n",
       "7  1.0 2013-01-01  1.0  2  train  foo"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "df22 = pd.DataFrame({'A':1.,\n",
    "                  'B':pd.Timestamp('20130101'),\n",
    "                  'C':pd.Series(1, index = range(4,8),dtype='float32'),\n",
    "                  'D':np.array([3,2]*2,dtype='int32'),\n",
    "                  'E':pd.Categorical(['test','train','test','train']),\n",
    "                  'F':'foo'})\n",
    "df22"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "'range' object is not callable",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-23-47115a565c14>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mli\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mlist\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mrange\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m9\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;36m2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      2\u001b[0m \u001b[0mli\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: 'range' object is not callable"
     ]
    }
   ],
   "source": [
    "li = list(range(5,9,2))\n",
    "li"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A           float64\n",
       "B    datetime64[ns]\n",
       "C           float32\n",
       "D             int32\n",
       "E          category\n",
       "F            object\n",
       "dtype: object"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看不同列的数据类型\n",
    "df22.dtypes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**小技巧：**  \n",
    "使用Tab自动补全功能会自动识别所有的属性以及自定义的列。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 查看数据"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "我们以平台获取的数据为例进行讲解："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>6.756725</td>\n",
       "      <td>5.189507</td>\n",
       "      <td>7.159406</td>\n",
       "      <td>8.869505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>0.705744</td>\n",
       "      <td>8.433346</td>\n",
       "      <td>5.528963</td>\n",
       "      <td>4.504458</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>2.937087</td>\n",
       "      <td>8.406702</td>\n",
       "      <td>9.184041</td>\n",
       "      <td>2.650301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>0.328357</td>\n",
       "      <td>5.427749</td>\n",
       "      <td>6.560164</td>\n",
       "      <td>8.142281</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>2.043023</td>\n",
       "      <td>2.279513</td>\n",
       "      <td>6.036387</td>\n",
       "      <td>8.845210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>0.767689</td>\n",
       "      <td>2.445295</td>\n",
       "      <td>4.942062</td>\n",
       "      <td>5.718906</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>3.078859</td>\n",
       "      <td>8.038801</td>\n",
       "      <td>2.075976</td>\n",
       "      <td>0.093437</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>1.543637</td>\n",
       "      <td>4.259877</td>\n",
       "      <td>4.310015</td>\n",
       "      <td>0.418999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>8.574750</td>\n",
       "      <td>9.722860</td>\n",
       "      <td>1.788176</td>\n",
       "      <td>0.470187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>4.367811</td>\n",
       "      <td>8.736579</td>\n",
       "      <td>7.656075</td>\n",
       "      <td>0.891855</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  6.756725  5.189507  7.159406  8.869505\n",
       "2019-06-02  0.705744  8.433346  5.528963  4.504458\n",
       "2019-06-03  2.937087  8.406702  9.184041  2.650301\n",
       "2019-06-04  0.328357  5.427749  6.560164  8.142281\n",
       "2019-06-05  2.043023  2.279513  6.036387  8.845210\n",
       "2019-06-06  0.767689  2.445295  4.942062  5.718906\n",
       "2019-06-07  3.078859  8.038801  2.075976  0.093437\n",
       "2019-06-08  1.543637  4.259877  4.310015  0.418999\n",
       "2019-06-09  8.574750  9.722860  1.788176  0.470187\n",
       "2019-06-10  4.367811  8.736579  7.656075  0.891855"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "dates = pd.date_range('20190601', periods=10)\n",
    "rand_data = np.random.rand(10,4)*10 # 10行4列\n",
    "cols = ['open','high','low','close']\n",
    "df23 = pd.DataFrame(rand_data, index=dates, columns=cols)\n",
    "df23"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 查看前、后几条数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>6.756725</td>\n",
       "      <td>5.189507</td>\n",
       "      <td>7.159406</td>\n",
       "      <td>8.869505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>0.705744</td>\n",
       "      <td>8.433346</td>\n",
       "      <td>5.528963</td>\n",
       "      <td>4.504458</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>2.937087</td>\n",
       "      <td>8.406702</td>\n",
       "      <td>9.184041</td>\n",
       "      <td>2.650301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>0.328357</td>\n",
       "      <td>5.427749</td>\n",
       "      <td>6.560164</td>\n",
       "      <td>8.142281</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>2.043023</td>\n",
       "      <td>2.279513</td>\n",
       "      <td>6.036387</td>\n",
       "      <td>8.845210</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  6.756725  5.189507  7.159406  8.869505\n",
       "2019-06-02  0.705744  8.433346  5.528963  4.504458\n",
       "2019-06-03  2.937087  8.406702  9.184041  2.650301\n",
       "2019-06-04  0.328357  5.427749  6.560164  8.142281\n",
       "2019-06-05  2.043023  2.279513  6.036387  8.845210"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 默认查看前5条数据\n",
    "df23.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>0.767689</td>\n",
       "      <td>2.445295</td>\n",
       "      <td>4.942062</td>\n",
       "      <td>5.718906</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>3.078859</td>\n",
       "      <td>8.038801</td>\n",
       "      <td>2.075976</td>\n",
       "      <td>0.093437</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>1.543637</td>\n",
       "      <td>4.259877</td>\n",
       "      <td>4.310015</td>\n",
       "      <td>0.418999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>8.574750</td>\n",
       "      <td>9.722860</td>\n",
       "      <td>1.788176</td>\n",
       "      <td>0.470187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>4.367811</td>\n",
       "      <td>8.736579</td>\n",
       "      <td>7.656075</td>\n",
       "      <td>0.891855</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-06  0.767689  2.445295  4.942062  5.718906\n",
       "2019-06-07  3.078859  8.038801  2.075976  0.093437\n",
       "2019-06-08  1.543637  4.259877  4.310015  0.418999\n",
       "2019-06-09  8.574750  9.722860  1.788176  0.470187\n",
       "2019-06-10  4.367811  8.736579  7.656075  0.891855"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 默认查看后5条数据\n",
    "df23.tail()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 显示索引、列和底层的numpy数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2019-06-01', '2019-06-02', '2019-06-03', '2019-06-04',\n",
       "               '2019-06-05', '2019-06-06', '2019-06-07', '2019-06-08',\n",
       "               '2019-06-09', '2019-06-10'],\n",
       "              dtype='datetime64[ns]', freq='D')"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看索引\n",
    "df23.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['open', 'high', 'low', 'close'], dtype='object')"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看列名\n",
    "df23.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[6.75672528, 5.18950687, 7.15940621, 8.86950511],\n",
       "       [0.70574355, 8.43334648, 5.52896277, 4.50445764],\n",
       "       [2.93708717, 8.40670181, 9.18404098, 2.65030062],\n",
       "       [0.32835668, 5.42774941, 6.56016351, 8.14228071],\n",
       "       [2.04302342, 2.27951268, 6.03638678, 8.84520997],\n",
       "       [0.76768886, 2.4452948 , 4.94206228, 5.71890609],\n",
       "       [3.07885879, 8.03880096, 2.07597561, 0.0934371 ],\n",
       "       [1.54363693, 4.25987669, 4.31001547, 0.41899949],\n",
       "       [8.5747498 , 9.72285965, 1.78817637, 0.47018678],\n",
       "       [4.36781136, 8.7365786 , 7.65607498, 0.89185531]])"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 查看DataFrame的值\n",
    "df23.values"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 对数据进行统计分析"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>10.000000</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>10.000000</td>\n",
       "      <td>10.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>3.110368</td>\n",
       "      <td>6.294023</td>\n",
       "      <td>5.524126</td>\n",
       "      <td>4.060514</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>2.736003</td>\n",
       "      <td>2.725283</td>\n",
       "      <td>2.347814</td>\n",
       "      <td>3.644566</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>0.328357</td>\n",
       "      <td>2.279513</td>\n",
       "      <td>1.788176</td>\n",
       "      <td>0.093437</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>0.961676</td>\n",
       "      <td>4.492284</td>\n",
       "      <td>4.468027</td>\n",
       "      <td>0.575604</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>2.490055</td>\n",
       "      <td>6.733275</td>\n",
       "      <td>5.782675</td>\n",
       "      <td>3.577379</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>4.045573</td>\n",
       "      <td>8.426685</td>\n",
       "      <td>7.009596</td>\n",
       "      <td>7.536437</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>8.574750</td>\n",
       "      <td>9.722860</td>\n",
       "      <td>9.184041</td>\n",
       "      <td>8.869505</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            open       high        low      close\n",
       "count  10.000000  10.000000  10.000000  10.000000\n",
       "mean    3.110368   6.294023   5.524126   4.060514\n",
       "std     2.736003   2.725283   2.347814   3.644566\n",
       "min     0.328357   2.279513   1.788176   0.093437\n",
       "25%     0.961676   4.492284   4.468027   0.575604\n",
       "50%     2.490055   6.733275   5.782675   3.577379\n",
       "75%     4.045573   8.426685   7.009596   7.536437\n",
       "max     8.574750   9.722860   9.184041   8.869505"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# describe()函数用于快速对数据进行统计汇总\n",
    "df23.describe()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 对数据的转置（transpose）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>2019-06-01 00:00:00</th>\n",
       "      <th>2019-06-02 00:00:00</th>\n",
       "      <th>2019-06-03 00:00:00</th>\n",
       "      <th>2019-06-04 00:00:00</th>\n",
       "      <th>2019-06-05 00:00:00</th>\n",
       "      <th>2019-06-06 00:00:00</th>\n",
       "      <th>2019-06-07 00:00:00</th>\n",
       "      <th>2019-06-08 00:00:00</th>\n",
       "      <th>2019-06-09 00:00:00</th>\n",
       "      <th>2019-06-10 00:00:00</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>open</th>\n",
       "      <td>6.756725</td>\n",
       "      <td>0.705744</td>\n",
       "      <td>2.937087</td>\n",
       "      <td>0.328357</td>\n",
       "      <td>2.043023</td>\n",
       "      <td>0.767689</td>\n",
       "      <td>3.078859</td>\n",
       "      <td>1.543637</td>\n",
       "      <td>8.574750</td>\n",
       "      <td>4.367811</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>high</th>\n",
       "      <td>5.189507</td>\n",
       "      <td>8.433346</td>\n",
       "      <td>8.406702</td>\n",
       "      <td>5.427749</td>\n",
       "      <td>2.279513</td>\n",
       "      <td>2.445295</td>\n",
       "      <td>8.038801</td>\n",
       "      <td>4.259877</td>\n",
       "      <td>9.722860</td>\n",
       "      <td>8.736579</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>low</th>\n",
       "      <td>7.159406</td>\n",
       "      <td>5.528963</td>\n",
       "      <td>9.184041</td>\n",
       "      <td>6.560164</td>\n",
       "      <td>6.036387</td>\n",
       "      <td>4.942062</td>\n",
       "      <td>2.075976</td>\n",
       "      <td>4.310015</td>\n",
       "      <td>1.788176</td>\n",
       "      <td>7.656075</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>close</th>\n",
       "      <td>8.869505</td>\n",
       "      <td>4.504458</td>\n",
       "      <td>2.650301</td>\n",
       "      <td>8.142281</td>\n",
       "      <td>8.845210</td>\n",
       "      <td>5.718906</td>\n",
       "      <td>0.093437</td>\n",
       "      <td>0.418999</td>\n",
       "      <td>0.470187</td>\n",
       "      <td>0.891855</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       2019-06-01  2019-06-02  2019-06-03  2019-06-04  2019-06-05  2019-06-06  \\\n",
       "open     6.756725    0.705744    2.937087    0.328357    2.043023    0.767689   \n",
       "high     5.189507    8.433346    8.406702    5.427749    2.279513    2.445295   \n",
       "low      7.159406    5.528963    9.184041    6.560164    6.036387    4.942062   \n",
       "close    8.869505    4.504458    2.650301    8.142281    8.845210    5.718906   \n",
       "\n",
       "       2019-06-07  2019-06-08  2019-06-09  2019-06-10  \n",
       "open     3.078859    1.543637    8.574750    4.367811  \n",
       "high     8.038801    4.259877    9.722860    8.736579  \n",
       "low      2.075976    4.310015    1.788176    7.656075  \n",
       "close    0.093437    0.418999    0.470187    0.891855  "
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 方法1\n",
    "df23.transpose()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>2019-06-01 00:00:00</th>\n",
       "      <th>2019-06-02 00:00:00</th>\n",
       "      <th>2019-06-03 00:00:00</th>\n",
       "      <th>2019-06-04 00:00:00</th>\n",
       "      <th>2019-06-05 00:00:00</th>\n",
       "      <th>2019-06-06 00:00:00</th>\n",
       "      <th>2019-06-07 00:00:00</th>\n",
       "      <th>2019-06-08 00:00:00</th>\n",
       "      <th>2019-06-09 00:00:00</th>\n",
       "      <th>2019-06-10 00:00:00</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>open</th>\n",
       "      <td>6.756725</td>\n",
       "      <td>0.705744</td>\n",
       "      <td>2.937087</td>\n",
       "      <td>0.328357</td>\n",
       "      <td>2.043023</td>\n",
       "      <td>0.767689</td>\n",
       "      <td>3.078859</td>\n",
       "      <td>1.543637</td>\n",
       "      <td>8.574750</td>\n",
       "      <td>4.367811</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>high</th>\n",
       "      <td>5.189507</td>\n",
       "      <td>8.433346</td>\n",
       "      <td>8.406702</td>\n",
       "      <td>5.427749</td>\n",
       "      <td>2.279513</td>\n",
       "      <td>2.445295</td>\n",
       "      <td>8.038801</td>\n",
       "      <td>4.259877</td>\n",
       "      <td>9.722860</td>\n",
       "      <td>8.736579</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>low</th>\n",
       "      <td>7.159406</td>\n",
       "      <td>5.528963</td>\n",
       "      <td>9.184041</td>\n",
       "      <td>6.560164</td>\n",
       "      <td>6.036387</td>\n",
       "      <td>4.942062</td>\n",
       "      <td>2.075976</td>\n",
       "      <td>4.310015</td>\n",
       "      <td>1.788176</td>\n",
       "      <td>7.656075</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>close</th>\n",
       "      <td>8.869505</td>\n",
       "      <td>4.504458</td>\n",
       "      <td>2.650301</td>\n",
       "      <td>8.142281</td>\n",
       "      <td>8.845210</td>\n",
       "      <td>5.718906</td>\n",
       "      <td>0.093437</td>\n",
       "      <td>0.418999</td>\n",
       "      <td>0.470187</td>\n",
       "      <td>0.891855</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       2019-06-01  2019-06-02  2019-06-03  2019-06-04  2019-06-05  2019-06-06  \\\n",
       "open     6.756725    0.705744    2.937087    0.328357    2.043023    0.767689   \n",
       "high     5.189507    8.433346    8.406702    5.427749    2.279513    2.445295   \n",
       "low      7.159406    5.528963    9.184041    6.560164    6.036387    4.942062   \n",
       "close    8.869505    4.504458    2.650301    8.142281    8.845210    5.718906   \n",
       "\n",
       "       2019-06-07  2019-06-08  2019-06-09  2019-06-10  \n",
       "open     3.078859    1.543637    8.574750    4.367811  \n",
       "high     8.038801    4.259877    9.722860    8.736579  \n",
       "low      2.075976    4.310015    1.788176    7.656075  \n",
       "close    0.093437    0.418999    0.470187    0.891855  "
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 方法2\n",
    "df23.T"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 按轴进行排序\n",
    "axis=0  index轴；  \n",
    "axis=1  column轴；    \n",
    "sort_index()是对索引名称进行升降序排列。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>6.756725</td>\n",
       "      <td>5.189507</td>\n",
       "      <td>7.159406</td>\n",
       "      <td>8.869505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>0.705744</td>\n",
       "      <td>8.433346</td>\n",
       "      <td>5.528963</td>\n",
       "      <td>4.504458</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>2.937087</td>\n",
       "      <td>8.406702</td>\n",
       "      <td>9.184041</td>\n",
       "      <td>2.650301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>0.328357</td>\n",
       "      <td>5.427749</td>\n",
       "      <td>6.560164</td>\n",
       "      <td>8.142281</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>2.043023</td>\n",
       "      <td>2.279513</td>\n",
       "      <td>6.036387</td>\n",
       "      <td>8.845210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>0.767689</td>\n",
       "      <td>2.445295</td>\n",
       "      <td>4.942062</td>\n",
       "      <td>5.718906</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>3.078859</td>\n",
       "      <td>8.038801</td>\n",
       "      <td>2.075976</td>\n",
       "      <td>0.093437</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>1.543637</td>\n",
       "      <td>4.259877</td>\n",
       "      <td>4.310015</td>\n",
       "      <td>0.418999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>8.574750</td>\n",
       "      <td>9.722860</td>\n",
       "      <td>1.788176</td>\n",
       "      <td>0.470187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>4.367811</td>\n",
       "      <td>8.736579</td>\n",
       "      <td>7.656075</td>\n",
       "      <td>0.891855</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  6.756725  5.189507  7.159406  8.869505\n",
       "2019-06-02  0.705744  8.433346  5.528963  4.504458\n",
       "2019-06-03  2.937087  8.406702  9.184041  2.650301\n",
       "2019-06-04  0.328357  5.427749  6.560164  8.142281\n",
       "2019-06-05  2.043023  2.279513  6.036387  8.845210\n",
       "2019-06-06  0.767689  2.445295  4.942062  5.718906\n",
       "2019-06-07  3.078859  8.038801  2.075976  0.093437\n",
       "2019-06-08  1.543637  4.259877  4.310015  0.418999\n",
       "2019-06-09  8.574750  9.722860  1.788176  0.470187\n",
       "2019-06-10  4.367811  8.736579  7.656075  0.891855"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df23"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>4.367811</td>\n",
       "      <td>8.736579</td>\n",
       "      <td>7.656075</td>\n",
       "      <td>0.891855</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>8.574750</td>\n",
       "      <td>9.722860</td>\n",
       "      <td>1.788176</td>\n",
       "      <td>0.470187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>1.543637</td>\n",
       "      <td>4.259877</td>\n",
       "      <td>4.310015</td>\n",
       "      <td>0.418999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>3.078859</td>\n",
       "      <td>8.038801</td>\n",
       "      <td>2.075976</td>\n",
       "      <td>0.093437</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>0.767689</td>\n",
       "      <td>2.445295</td>\n",
       "      <td>4.942062</td>\n",
       "      <td>5.718906</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>2.043023</td>\n",
       "      <td>2.279513</td>\n",
       "      <td>6.036387</td>\n",
       "      <td>8.845210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>0.328357</td>\n",
       "      <td>5.427749</td>\n",
       "      <td>6.560164</td>\n",
       "      <td>8.142281</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>2.937087</td>\n",
       "      <td>8.406702</td>\n",
       "      <td>9.184041</td>\n",
       "      <td>2.650301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>0.705744</td>\n",
       "      <td>8.433346</td>\n",
       "      <td>5.528963</td>\n",
       "      <td>4.504458</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>6.756725</td>\n",
       "      <td>5.189507</td>\n",
       "      <td>7.159406</td>\n",
       "      <td>8.869505</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-10  4.367811  8.736579  7.656075  0.891855\n",
       "2019-06-09  8.574750  9.722860  1.788176  0.470187\n",
       "2019-06-08  1.543637  4.259877  4.310015  0.418999\n",
       "2019-06-07  3.078859  8.038801  2.075976  0.093437\n",
       "2019-06-06  0.767689  2.445295  4.942062  5.718906\n",
       "2019-06-05  2.043023  2.279513  6.036387  8.845210\n",
       "2019-06-04  0.328357  5.427749  6.560164  8.142281\n",
       "2019-06-03  2.937087  8.406702  9.184041  2.650301\n",
       "2019-06-02  0.705744  8.433346  5.528963  4.504458\n",
       "2019-06-01  6.756725  5.189507  7.159406  8.869505"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ascending=True(升序排列)；ascending=False(降序排列)\n",
    "df23.sort_index(axis=0,ascending=False) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>close</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>open</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>8.869505</td>\n",
       "      <td>5.189507</td>\n",
       "      <td>7.159406</td>\n",
       "      <td>6.756725</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>4.504458</td>\n",
       "      <td>8.433346</td>\n",
       "      <td>5.528963</td>\n",
       "      <td>0.705744</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>2.650301</td>\n",
       "      <td>8.406702</td>\n",
       "      <td>9.184041</td>\n",
       "      <td>2.937087</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>8.142281</td>\n",
       "      <td>5.427749</td>\n",
       "      <td>6.560164</td>\n",
       "      <td>0.328357</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>8.845210</td>\n",
       "      <td>2.279513</td>\n",
       "      <td>6.036387</td>\n",
       "      <td>2.043023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>5.718906</td>\n",
       "      <td>2.445295</td>\n",
       "      <td>4.942062</td>\n",
       "      <td>0.767689</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>0.093437</td>\n",
       "      <td>8.038801</td>\n",
       "      <td>2.075976</td>\n",
       "      <td>3.078859</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>0.418999</td>\n",
       "      <td>4.259877</td>\n",
       "      <td>4.310015</td>\n",
       "      <td>1.543637</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>0.470187</td>\n",
       "      <td>9.722860</td>\n",
       "      <td>1.788176</td>\n",
       "      <td>8.574750</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>0.891855</td>\n",
       "      <td>8.736579</td>\n",
       "      <td>7.656075</td>\n",
       "      <td>4.367811</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               close      high       low      open\n",
       "2019-06-01  8.869505  5.189507  7.159406  6.756725\n",
       "2019-06-02  4.504458  8.433346  5.528963  0.705744\n",
       "2019-06-03  2.650301  8.406702  9.184041  2.937087\n",
       "2019-06-04  8.142281  5.427749  6.560164  0.328357\n",
       "2019-06-05  8.845210  2.279513  6.036387  2.043023\n",
       "2019-06-06  5.718906  2.445295  4.942062  0.767689\n",
       "2019-06-07  0.093437  8.038801  2.075976  3.078859\n",
       "2019-06-08  0.418999  4.259877  4.310015  1.543637\n",
       "2019-06-09  0.470187  9.722860  1.788176  8.574750\n",
       "2019-06-10  0.891855  8.736579  7.656075  4.367811"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# axis=1等于axis='columns'\n",
    "df23.sort_index(axis=1,ascending=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 按指定列进行排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>0.328357</td>\n",
       "      <td>5.427749</td>\n",
       "      <td>6.560164</td>\n",
       "      <td>8.142281</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>0.705744</td>\n",
       "      <td>8.433346</td>\n",
       "      <td>5.528963</td>\n",
       "      <td>4.504458</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>0.767689</td>\n",
       "      <td>2.445295</td>\n",
       "      <td>4.942062</td>\n",
       "      <td>5.718906</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>1.543637</td>\n",
       "      <td>4.259877</td>\n",
       "      <td>4.310015</td>\n",
       "      <td>0.418999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>2.043023</td>\n",
       "      <td>2.279513</td>\n",
       "      <td>6.036387</td>\n",
       "      <td>8.845210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>2.937087</td>\n",
       "      <td>8.406702</td>\n",
       "      <td>9.184041</td>\n",
       "      <td>2.650301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>3.078859</td>\n",
       "      <td>8.038801</td>\n",
       "      <td>2.075976</td>\n",
       "      <td>0.093437</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>4.367811</td>\n",
       "      <td>8.736579</td>\n",
       "      <td>7.656075</td>\n",
       "      <td>0.891855</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>6.756725</td>\n",
       "      <td>5.189507</td>\n",
       "      <td>7.159406</td>\n",
       "      <td>8.869505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>8.574750</td>\n",
       "      <td>9.722860</td>\n",
       "      <td>1.788176</td>\n",
       "      <td>0.470187</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-04  0.328357  5.427749  6.560164  8.142281\n",
       "2019-06-02  0.705744  8.433346  5.528963  4.504458\n",
       "2019-06-06  0.767689  2.445295  4.942062  5.718906\n",
       "2019-06-08  1.543637  4.259877  4.310015  0.418999\n",
       "2019-06-05  2.043023  2.279513  6.036387  8.845210\n",
       "2019-06-03  2.937087  8.406702  9.184041  2.650301\n",
       "2019-06-07  3.078859  8.038801  2.075976  0.093437\n",
       "2019-06-10  4.367811  8.736579  7.656075  0.891855\n",
       "2019-06-01  6.756725  5.189507  7.159406  8.869505\n",
       "2019-06-09  8.574750  9.722860  1.788176  0.470187"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 对open列的数据进行升序排列\n",
    "df23.sort_values(by='open',ascending=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>8.574750</td>\n",
       "      <td>9.722860</td>\n",
       "      <td>1.788176</td>\n",
       "      <td>0.470187</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>6.756725</td>\n",
       "      <td>5.189507</td>\n",
       "      <td>7.159406</td>\n",
       "      <td>8.869505</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>4.367811</td>\n",
       "      <td>8.736579</td>\n",
       "      <td>7.656075</td>\n",
       "      <td>0.891855</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>3.078859</td>\n",
       "      <td>8.038801</td>\n",
       "      <td>2.075976</td>\n",
       "      <td>0.093437</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>2.937087</td>\n",
       "      <td>8.406702</td>\n",
       "      <td>9.184041</td>\n",
       "      <td>2.650301</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>2.043023</td>\n",
       "      <td>2.279513</td>\n",
       "      <td>6.036387</td>\n",
       "      <td>8.845210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>1.543637</td>\n",
       "      <td>4.259877</td>\n",
       "      <td>4.310015</td>\n",
       "      <td>0.418999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>0.767689</td>\n",
       "      <td>2.445295</td>\n",
       "      <td>4.942062</td>\n",
       "      <td>5.718906</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>0.705744</td>\n",
       "      <td>8.433346</td>\n",
       "      <td>5.528963</td>\n",
       "      <td>4.504458</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>0.328357</td>\n",
       "      <td>5.427749</td>\n",
       "      <td>6.560164</td>\n",
       "      <td>8.142281</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-09  8.574750  9.722860  1.788176  0.470187\n",
       "2019-06-01  6.756725  5.189507  7.159406  8.869505\n",
       "2019-06-10  4.367811  8.736579  7.656075  0.891855\n",
       "2019-06-07  3.078859  8.038801  2.075976  0.093437\n",
       "2019-06-03  2.937087  8.406702  9.184041  2.650301\n",
       "2019-06-05  2.043023  2.279513  6.036387  8.845210\n",
       "2019-06-08  1.543637  4.259877  4.310015  0.418999\n",
       "2019-06-06  0.767689  2.445295  4.942062  5.718906\n",
       "2019-06-02  0.705744  8.433346  5.528963  4.504458\n",
       "2019-06-04  0.328357  5.427749  6.560164  8.142281"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 对open列的数据进行降序排列\n",
    "df23.sort_values(by='open',ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 选择数据\n",
    "### 通过下标选择数据\n",
    "df['open']，df.open两个语句是等效的，都是返回 df 名称为 open 列的数据，返回一个 Series。  \n",
    "df[0:3], df['2017-06-01':'2017-06-05']下标索引选取的是 DataFrame 的记录。   \n",
    "\n",
    "与 List 相同 DataFrame 的下标也是从0开始，区间索引的话，为一个左闭右开的区间，即[0：3]选取的为0-2三条记录。  \n",
    "还可以用起始的索引名称和结束索引名称选取数据,如：df['a':'b']。  \n",
    "\n",
    "需要注意的是使用起始索引名称和结束索引名称时，也会包含结束索引的数据。以上两种方式返回的都是DataFrame。  \n",
    "具体看下方示例： "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>6.181523</td>\n",
       "      <td>5.492165</td>\n",
       "      <td>9.305931</td>\n",
       "      <td>7.899466</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>0.112662</td>\n",
       "      <td>1.905660</td>\n",
       "      <td>0.960280</td>\n",
       "      <td>0.486597</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>8.108670</td>\n",
       "      <td>6.100856</td>\n",
       "      <td>3.785242</td>\n",
       "      <td>6.402280</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>1.094156</td>\n",
       "      <td>3.505879</td>\n",
       "      <td>2.343761</td>\n",
       "      <td>8.884680</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>0.764807</td>\n",
       "      <td>5.441474</td>\n",
       "      <td>3.895429</td>\n",
       "      <td>5.410725</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>7.993234</td>\n",
       "      <td>2.047902</td>\n",
       "      <td>4.348476</td>\n",
       "      <td>6.477967</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>9.149483</td>\n",
       "      <td>2.071877</td>\n",
       "      <td>9.135787</td>\n",
       "      <td>5.081943</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>8.908368</td>\n",
       "      <td>8.474768</td>\n",
       "      <td>7.605822</td>\n",
       "      <td>9.800321</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>6.175139</td>\n",
       "      <td>7.385208</td>\n",
       "      <td>6.920521</td>\n",
       "      <td>5.867950</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>6.192683</td>\n",
       "      <td>4.569689</td>\n",
       "      <td>6.383989</td>\n",
       "      <td>6.992235</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  6.181523  5.492165  9.305931  7.899466\n",
       "2019-06-02  0.112662  1.905660  0.960280  0.486597\n",
       "2019-06-03  8.108670  6.100856  3.785242  6.402280\n",
       "2019-06-04  1.094156  3.505879  2.343761  8.884680\n",
       "2019-06-05  0.764807  5.441474  3.895429  5.410725\n",
       "2019-06-06  7.993234  2.047902  4.348476  6.477967\n",
       "2019-06-07  9.149483  2.071877  9.135787  5.081943\n",
       "2019-06-08  8.908368  8.474768  7.605822  9.800321\n",
       "2019-06-09  6.175139  7.385208  6.920521  5.867950\n",
       "2019-06-10  6.192683  4.569689  6.383989  6.992235"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "dates = pd.date_range('20190601', periods=10)\n",
    "rand_datas = np.random.rand(10,4)*10 # 10行4列\n",
    "list = ['open','high','low','close']\n",
    "df24 = pd.DataFrame(rand_datas, index=dates, columns=list)\n",
    "df24"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 选择一列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2019-06-01    6.181523\n",
       "2019-06-02    0.112662\n",
       "2019-06-03    8.108670\n",
       "2019-06-04    1.094156\n",
       "2019-06-05    0.764807\n",
       "2019-06-06    7.993234\n",
       "2019-06-07    9.149483\n",
       "2019-06-08    8.908368\n",
       "2019-06-09    6.175139\n",
       "2019-06-10    6.192683\n",
       "Freq: D, Name: open, dtype: float64"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选择open列的数据\n",
    "df24['open'] "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 选择多列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>6.181523</td>\n",
       "      <td>7.899466</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>0.112662</td>\n",
       "      <td>0.486597</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>8.108670</td>\n",
       "      <td>6.402280</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>1.094156</td>\n",
       "      <td>8.884680</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>0.764807</td>\n",
       "      <td>5.410725</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>7.993234</td>\n",
       "      <td>6.477967</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-07</th>\n",
       "      <td>9.149483</td>\n",
       "      <td>5.081943</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-08</th>\n",
       "      <td>8.908368</td>\n",
       "      <td>9.800321</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-09</th>\n",
       "      <td>6.175139</td>\n",
       "      <td>5.867950</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-10</th>\n",
       "      <td>6.192683</td>\n",
       "      <td>6.992235</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open     close\n",
       "2019-06-01  6.181523  7.899466\n",
       "2019-06-02  0.112662  0.486597\n",
       "2019-06-03  8.108670  6.402280\n",
       "2019-06-04  1.094156  8.884680\n",
       "2019-06-05  0.764807  5.410725\n",
       "2019-06-06  7.993234  6.477967\n",
       "2019-06-07  9.149483  5.081943\n",
       "2019-06-08  8.908368  9.800321\n",
       "2019-06-09  6.175139  5.867950\n",
       "2019-06-10  6.192683  6.992235"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df24[['open','close']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 选择多行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>6.181523</td>\n",
       "      <td>5.492165</td>\n",
       "      <td>9.305931</td>\n",
       "      <td>7.899466</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>0.112662</td>\n",
       "      <td>1.905660</td>\n",
       "      <td>0.960280</td>\n",
       "      <td>0.486597</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>8.108670</td>\n",
       "      <td>6.100856</td>\n",
       "      <td>3.785242</td>\n",
       "      <td>6.402280</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  6.181523  5.492165  9.305931  7.899466\n",
       "2019-06-02  0.112662  1.905660  0.960280  0.486597\n",
       "2019-06-03  8.108670  6.100856  3.785242  6.402280"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 位置索引\n",
    "df24[0:3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>6.181523</td>\n",
       "      <td>5.492165</td>\n",
       "      <td>9.305931</td>\n",
       "      <td>7.899466</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>0.112662</td>\n",
       "      <td>1.905660</td>\n",
       "      <td>0.960280</td>\n",
       "      <td>0.486597</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>8.108670</td>\n",
       "      <td>6.100856</td>\n",
       "      <td>3.785242</td>\n",
       "      <td>6.402280</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>1.094156</td>\n",
       "      <td>3.505879</td>\n",
       "      <td>2.343761</td>\n",
       "      <td>8.884680</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>0.764807</td>\n",
       "      <td>5.441474</td>\n",
       "      <td>3.895429</td>\n",
       "      <td>5.410725</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  6.181523  5.492165  9.305931  7.899466\n",
       "2019-06-02  0.112662  1.905660  0.960280  0.486597\n",
       "2019-06-03  8.108670  6.100856  3.785242  6.402280\n",
       "2019-06-04  1.094156  3.505879  2.343761  8.884680\n",
       "2019-06-05  0.764807  5.441474  3.895429  5.410725"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 标签索引\n",
    "df24['2019-06-01':'2019-06-05']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 通过标签选取数据\n",
    "- df.loc[行标签,列标签]  \n",
    "- df.loc['a':'b'] #选取 ab 两行数据  \n",
    "- df.loc[:,'open'] #选取 open 列的数据   \n",
    "\n",
    "df.loc 的第一个参数是行标签，第二个参数为列标签（可选参数，默认为所有列标签），两个参数既可以是列表也可以是单个字符。如果两个参数都为列表则返回的是 DataFrame，否则，则为 Series。\n",
    "\n",
    "PS：loc为location的缩写。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6.925296504971658"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选取行交列的单个数值\n",
    "df2_5.loc['2019-06-01','open']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-06-01</th>\n",
       "      <td>6.925297</td>\n",
       "      <td>3.986475</td>\n",
       "      <td>7.200105</td>\n",
       "      <td>3.319409</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-02</th>\n",
       "      <td>0.931925</td>\n",
       "      <td>0.096879</td>\n",
       "      <td>5.133140</td>\n",
       "      <td>0.403244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-03</th>\n",
       "      <td>2.777795</td>\n",
       "      <td>8.999843</td>\n",
       "      <td>5.374552</td>\n",
       "      <td>2.534591</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-04</th>\n",
       "      <td>4.907680</td>\n",
       "      <td>0.466965</td>\n",
       "      <td>2.603271</td>\n",
       "      <td>0.127082</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-05</th>\n",
       "      <td>4.393066</td>\n",
       "      <td>0.135219</td>\n",
       "      <td>6.429140</td>\n",
       "      <td>4.298915</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-06-06</th>\n",
       "      <td>8.145999</td>\n",
       "      <td>4.034788</td>\n",
       "      <td>6.914401</td>\n",
       "      <td>2.436211</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-06-01  6.925297  3.986475  7.200105  3.319409\n",
       "2019-06-02  0.931925  0.096879  5.133140  0.403244\n",
       "2019-06-03  2.777795  8.999843  5.374552  2.534591\n",
       "2019-06-04  4.907680  0.466965  2.603271  0.127082\n",
       "2019-06-05  4.393066  0.135219  6.429140  4.298915\n",
       "2019-06-06  8.145999  4.034788  6.914401  2.436211"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#选取区间行数据\n",
    "df2_5.loc['2019-06-01':'2019-06-06']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2019-06-01    6.925297\n",
       "2019-06-02    0.931925\n",
       "2019-06-03    2.777795\n",
       "2019-06-04    4.907680\n",
       "2019-06-05    4.393066\n",
       "2019-06-06    8.145999\n",
       "2019-06-07    7.646782\n",
       "2019-06-08    0.347201\n",
       "2019-06-09    3.929119\n",
       "2019-06-10    4.090959\n",
       "Freq: D, Name: open, dtype: float64"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#选取所有行的 open 列的数据\n",
    "df2_5.loc[:,'open']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2019-06-01    6.925297\n",
       "2019-06-02    0.931925\n",
       "2019-06-03    2.777795\n",
       "2019-06-04    4.907680\n",
       "2019-06-05    4.393066\n",
       "2019-06-06    8.145999\n",
       "Freq: D, Name: open, dtype: float64"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选取区间行交指定列的数据\n",
    "df2_5.loc['2019-06-01':'2019-06-06','open']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 通过位置选取数据\n",
    "- df.iloc[行位置,列位置]\n",
    "- df.iloc[1,1] #选取第二行，第二列的值，返回的为单个值\n",
    "- df.iloc[[0,2],:] #选取第一行及第三行的数据\n",
    "- df.iloc[0:2,:] #选取第一行到第三行（不包含）的数据\n",
    "- df.iloc[:,1] #选取所有记录的第二列的值，返回的为一个Series\n",
    "- df.iloc[1,:] #选取第一行数据，返回的为一个Series\n",
    "\n",
    "PS：iloc 则为 integer & location 的缩写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-01</th>\n",
       "      <td>2.594537</td>\n",
       "      <td>9.624780</td>\n",
       "      <td>6.708913</td>\n",
       "      <td>0.041023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-02</th>\n",
       "      <td>1.922037</td>\n",
       "      <td>2.904484</td>\n",
       "      <td>0.060149</td>\n",
       "      <td>9.858212</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-03</th>\n",
       "      <td>9.404449</td>\n",
       "      <td>7.494163</td>\n",
       "      <td>5.166609</td>\n",
       "      <td>4.801551</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-04</th>\n",
       "      <td>4.949363</td>\n",
       "      <td>9.777113</td>\n",
       "      <td>5.421154</td>\n",
       "      <td>7.677120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-05</th>\n",
       "      <td>6.186702</td>\n",
       "      <td>9.163937</td>\n",
       "      <td>4.745684</td>\n",
       "      <td>6.745426</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-06</th>\n",
       "      <td>7.759351</td>\n",
       "      <td>5.381608</td>\n",
       "      <td>6.000137</td>\n",
       "      <td>8.779823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-07</th>\n",
       "      <td>8.148540</td>\n",
       "      <td>9.652254</td>\n",
       "      <td>6.769660</td>\n",
       "      <td>1.953244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-08</th>\n",
       "      <td>5.151098</td>\n",
       "      <td>8.146486</td>\n",
       "      <td>1.421423</td>\n",
       "      <td>1.413568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-09</th>\n",
       "      <td>5.589647</td>\n",
       "      <td>9.442603</td>\n",
       "      <td>5.525858</td>\n",
       "      <td>6.506602</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-10</th>\n",
       "      <td>5.673073</td>\n",
       "      <td>9.184724</td>\n",
       "      <td>5.594822</td>\n",
       "      <td>2.483338</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-01-01  2.594537  9.624780  6.708913  0.041023\n",
       "2019-01-02  1.922037  2.904484  0.060149  9.858212\n",
       "2019-01-03  9.404449  7.494163  5.166609  4.801551\n",
       "2019-01-04  4.949363  9.777113  5.421154  7.677120\n",
       "2019-01-05  6.186702  9.163937  4.745684  6.745426\n",
       "2019-01-06  7.759351  5.381608  6.000137  8.779823\n",
       "2019-01-07  8.148540  9.652254  6.769660  1.953244\n",
       "2019-01-08  5.151098  8.146486  1.421423  1.413568\n",
       "2019-01-09  5.589647  9.442603  5.525858  6.506602\n",
       "2019-01-10  5.673073  9.184724  5.594822  2.483338"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "dates = pd.date_range('20190101', periods=10)\n",
    "distribution = np.random.rand(10,4)*10 # 10行4列\n",
    "list = ['open','high','low','close']\n",
    "df2_5 = pd.DataFrame(distribution, index=dates, columns=list)\n",
    "df2_5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.904484318213465"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选取第2行交第2列的值，返回单个值\n",
    "df2_5.iloc[1,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-01</th>\n",
       "      <td>2.594537</td>\n",
       "      <td>9.624780</td>\n",
       "      <td>6.708913</td>\n",
       "      <td>0.041023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-03</th>\n",
       "      <td>9.404449</td>\n",
       "      <td>7.494163</td>\n",
       "      <td>5.166609</td>\n",
       "      <td>4.801551</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-01-01  2.594537  9.624780  6.708913  0.041023\n",
       "2019-01-03  9.404449  7.494163  5.166609  4.801551"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选取第1行、第3行交所有列的数据（非区间）\n",
    "df2_5.iloc[[0,2],:] "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2019-01-01    9.624780\n",
       "2019-01-02    2.904484\n",
       "2019-01-03    7.494163\n",
       "2019-01-04    9.777113\n",
       "2019-01-05    9.163937\n",
       "2019-01-06    5.381608\n",
       "2019-01-07    9.652254\n",
       "2019-01-08    8.146486\n",
       "2019-01-09    9.442603\n",
       "2019-01-10    9.184724\n",
       "Freq: D, Name: high, dtype: float64"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选取所有行交第2列的值，返回的为一个Series\n",
    "df2_5.iloc[:,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "open     1.922037\n",
       "high     2.904484\n",
       "low      0.060149\n",
       "close    9.858212\n",
       "Name: 2019-01-02 00:00:00, dtype: float64"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选取第2行交所有列的数据，返回的为一个Series\n",
    "df2_5.iloc[1,:] "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 使用ix获取数据\n",
    "更广义的切片方式是使用.ix。  \n",
    "它会自动根据给出的索引类型判断是使用**位置**还是**标签**进行切片。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\pcApp\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:1: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "5.048632660493169"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2_5.ix[1,1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\pcApp\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:1: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-01</th>\n",
       "      <td>0.833175</td>\n",
       "      <td>4.292431</td>\n",
       "      <td>5.267151</td>\n",
       "      <td>7.623721</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-02</th>\n",
       "      <td>1.578833</td>\n",
       "      <td>5.048633</td>\n",
       "      <td>5.303261</td>\n",
       "      <td>6.885764</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-03</th>\n",
       "      <td>2.099065</td>\n",
       "      <td>9.819080</td>\n",
       "      <td>1.942463</td>\n",
       "      <td>2.817264</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-04</th>\n",
       "      <td>6.976177</td>\n",
       "      <td>7.707388</td>\n",
       "      <td>3.072416</td>\n",
       "      <td>5.986185</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-05</th>\n",
       "      <td>0.146856</td>\n",
       "      <td>1.714931</td>\n",
       "      <td>9.314118</td>\n",
       "      <td>8.710319</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-06</th>\n",
       "      <td>4.501978</td>\n",
       "      <td>7.462104</td>\n",
       "      <td>6.252740</td>\n",
       "      <td>1.616744</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-01-01  0.833175  4.292431  5.267151  7.623721\n",
       "2019-01-02  1.578833  5.048633  5.303261  6.885764\n",
       "2019-01-03  2.099065  9.819080  1.942463  2.817264\n",
       "2019-01-04  6.976177  7.707388  3.072416  5.986185\n",
       "2019-01-05  0.146856  1.714931  9.314118  8.710319\n",
       "2019-01-06  4.501978  7.462104  6.252740  1.616744"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2_5.ix['2019-01-01':'2019-01-06']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\pcApp\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:2: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "  \n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "1.9424628126608412"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 位置索引+位置索引\n",
    "df2_5.ix['2019-01-03','low']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\pcApp\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:2: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "  \n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "6.8857637965972165"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 位置索引+标签索引\n",
    "df2_5.ix[1,'close']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\pcApp\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:2: DeprecationWarning: \n",
      ".ix is deprecated. Please use\n",
      ".loc for label based indexing or\n",
      ".iloc for positional indexing\n",
      "\n",
      "See the documentation here:\n",
      "http://pandas.pydata.org/pandas-docs/stable/indexing.html#ix-indexer-is-deprecated\n",
      "  \n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "2.0990649246754134"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 标签索引+位置索引\n",
    "df2_5.ix['2019-01-03',0]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 通过逻辑指针进行数据切片\n",
    "df[逻辑条件]\n",
    "- df[df.one >= 2] #单个逻辑条件\n",
    "- df[(df.one >=1 ) & (df.one < 3) ] #多个逻辑条件组合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-01</th>\n",
       "      <td>2.594537</td>\n",
       "      <td>9.624780</td>\n",
       "      <td>6.708913</td>\n",
       "      <td>0.041023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-02</th>\n",
       "      <td>1.922037</td>\n",
       "      <td>2.904484</td>\n",
       "      <td>0.060149</td>\n",
       "      <td>9.858212</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-03</th>\n",
       "      <td>9.404449</td>\n",
       "      <td>7.494163</td>\n",
       "      <td>5.166609</td>\n",
       "      <td>4.801551</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-04</th>\n",
       "      <td>4.949363</td>\n",
       "      <td>9.777113</td>\n",
       "      <td>5.421154</td>\n",
       "      <td>7.677120</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-05</th>\n",
       "      <td>6.186702</td>\n",
       "      <td>9.163937</td>\n",
       "      <td>4.745684</td>\n",
       "      <td>6.745426</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-06</th>\n",
       "      <td>7.759351</td>\n",
       "      <td>5.381608</td>\n",
       "      <td>6.000137</td>\n",
       "      <td>8.779823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-07</th>\n",
       "      <td>8.148540</td>\n",
       "      <td>9.652254</td>\n",
       "      <td>6.769660</td>\n",
       "      <td>1.953244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-08</th>\n",
       "      <td>5.151098</td>\n",
       "      <td>8.146486</td>\n",
       "      <td>1.421423</td>\n",
       "      <td>1.413568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-09</th>\n",
       "      <td>5.589647</td>\n",
       "      <td>9.442603</td>\n",
       "      <td>5.525858</td>\n",
       "      <td>6.506602</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-10</th>\n",
       "      <td>5.673073</td>\n",
       "      <td>9.184724</td>\n",
       "      <td>5.594822</td>\n",
       "      <td>2.483338</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-01-01  2.594537  9.624780  6.708913  0.041023\n",
       "2019-01-02  1.922037  2.904484  0.060149  9.858212\n",
       "2019-01-03  9.404449  7.494163  5.166609  4.801551\n",
       "2019-01-04  4.949363  9.777113  5.421154  7.677120\n",
       "2019-01-05  6.186702  9.163937  4.745684  6.745426\n",
       "2019-01-06  7.759351  5.381608  6.000137  8.779823\n",
       "2019-01-07  8.148540  9.652254  6.769660  1.953244\n",
       "2019-01-08  5.151098  8.146486  1.421423  1.413568\n",
       "2019-01-09  5.589647  9.442603  5.525858  6.506602\n",
       "2019-01-10  5.673073  9.184724  5.594822  2.483338"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2_5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-03</th>\n",
       "      <td>9.404449</td>\n",
       "      <td>7.494163</td>\n",
       "      <td>5.166609</td>\n",
       "      <td>4.801551</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-06</th>\n",
       "      <td>7.759351</td>\n",
       "      <td>5.381608</td>\n",
       "      <td>6.000137</td>\n",
       "      <td>8.779823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-07</th>\n",
       "      <td>8.148540</td>\n",
       "      <td>9.652254</td>\n",
       "      <td>6.769660</td>\n",
       "      <td>1.953244</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-01-03  9.404449  7.494163  5.166609  4.801551\n",
       "2019-01-06  7.759351  5.381608  6.000137  8.779823\n",
       "2019-01-07  8.148540  9.652254  6.769660  1.953244"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 筛选出open大于6.8的数据\n",
    "df2_5[df2_5.open>6.8]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-03</th>\n",
       "      <td>9.404449</td>\n",
       "      <td>7.494163</td>\n",
       "      <td>5.166609</td>\n",
       "      <td>4.801551</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-07</th>\n",
       "      <td>8.148540</td>\n",
       "      <td>9.652254</td>\n",
       "      <td>6.769660</td>\n",
       "      <td>1.953244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-08</th>\n",
       "      <td>5.151098</td>\n",
       "      <td>8.146486</td>\n",
       "      <td>1.421423</td>\n",
       "      <td>1.413568</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-10</th>\n",
       "      <td>5.673073</td>\n",
       "      <td>9.184724</td>\n",
       "      <td>5.594822</td>\n",
       "      <td>2.483338</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high       low     close\n",
       "2019-01-03  9.404449  7.494163  5.166609  4.801551\n",
       "2019-01-07  8.148540  9.652254  6.769660  1.953244\n",
       "2019-01-08  5.151098  8.146486  1.421423  1.413568\n",
       "2019-01-10  5.673073  9.184724  5.594822  2.483338"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 筛选出open大于2.8，并且close<6的数据\n",
    "df2_5[(df2_5.open>2.8)&(df2_5.close<6)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-01</th>\n",
       "      <td>NaN</td>\n",
       "      <td>9.624780</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-02</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>9.858212</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-03</th>\n",
       "      <td>9.404449</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-04</th>\n",
       "      <td>NaN</td>\n",
       "      <td>9.777113</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-05</th>\n",
       "      <td>NaN</td>\n",
       "      <td>9.163937</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-06</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>8.779823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-07</th>\n",
       "      <td>8.148540</td>\n",
       "      <td>9.652254</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-08</th>\n",
       "      <td>NaN</td>\n",
       "      <td>8.146486</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-09</th>\n",
       "      <td>NaN</td>\n",
       "      <td>9.442603</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-10</th>\n",
       "      <td>NaN</td>\n",
       "      <td>9.184724</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high  low     close\n",
       "2019-01-01       NaN  9.624780  NaN       NaN\n",
       "2019-01-02       NaN       NaN  NaN  9.858212\n",
       "2019-01-03  9.404449       NaN  NaN       NaN\n",
       "2019-01-04       NaN  9.777113  NaN       NaN\n",
       "2019-01-05       NaN  9.163937  NaN       NaN\n",
       "2019-01-06       NaN       NaN  NaN  8.779823\n",
       "2019-01-07  8.148540  9.652254  NaN       NaN\n",
       "2019-01-08       NaN  8.146486  NaN       NaN\n",
       "2019-01-09       NaN  9.442603  NaN       NaN\n",
       "2019-01-10       NaN  9.184724  NaN       NaN"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 显示特定条件的数据\n",
    "df2_5[df2_5>8]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "可以看到df2_5中小于8的数都变成了NaN。  \n",
    "\n",
    "下面我们接着把小于8的数赋值为0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-01</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.624780</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-02</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>9.858212</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-03</th>\n",
       "      <td>9.404449</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-04</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.777113</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-05</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.163937</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-06</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>8.779823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-07</th>\n",
       "      <td>8.148540</td>\n",
       "      <td>9.652254</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-08</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>8.146486</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-09</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.442603</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-10</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.184724</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high  low     close\n",
       "2019-01-01  0.000000  9.624780  0.0  0.000000\n",
       "2019-01-02  0.000000  0.000000  0.0  9.858212\n",
       "2019-01-03  9.404449  0.000000  0.0  0.000000\n",
       "2019-01-04  0.000000  9.777113  0.0  0.000000\n",
       "2019-01-05  0.000000  9.163937  0.0  0.000000\n",
       "2019-01-06  0.000000  0.000000  0.0  8.779823\n",
       "2019-01-07  8.148540  9.652254  0.0  0.000000\n",
       "2019-01-08  0.000000  8.146486  0.0  0.000000\n",
       "2019-01-09  0.000000  9.442603  0.0  0.000000\n",
       "2019-01-10  0.000000  9.184724  0.0  0.000000"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 把特定条件的数据赋值为某特定数\n",
    "df2_5[df2_5<8] = 0\n",
    "df2_5"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 使用isin()方法过滤指定列中的数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-01</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.624780</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-02</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>9.858212</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-03</th>\n",
       "      <td>9.404449</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-04</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.777113</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-05</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.163937</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-06</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>8.779823</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-07</th>\n",
       "      <td>8.148540</td>\n",
       "      <td>9.652254</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-08</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>8.146486</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-09</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.442603</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-10</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>9.184724</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open      high  low     close\n",
       "2019-01-01  0.000000  9.624780  0.0  0.000000\n",
       "2019-01-02  0.000000  0.000000  0.0  9.858212\n",
       "2019-01-03  9.404449  0.000000  0.0  0.000000\n",
       "2019-01-04  0.000000  9.777113  0.0  0.000000\n",
       "2019-01-05  0.000000  9.163937  0.0  0.000000\n",
       "2019-01-06  0.000000  0.000000  0.0  8.779823\n",
       "2019-01-07  8.148540  9.652254  0.0  0.000000\n",
       "2019-01-08  0.000000  8.146486  0.0  0.000000\n",
       "2019-01-09  0.000000  9.442603  0.0  0.000000\n",
       "2019-01-10  0.000000  9.184724  0.0  0.000000"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df2_5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>open</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2019-01-02</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>9.858212</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-03</th>\n",
       "      <td>9.404449</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-06</th>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>8.779823</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                open  high  low     close\n",
       "2019-01-02  0.000000   0.0  0.0  9.858212\n",
       "2019-01-03  9.404449   0.0  0.0  0.000000\n",
       "2019-01-06  0.000000   0.0  0.0  8.779823"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 选取 high 列中数为 0 和 9 的数。\n",
    "df2_5[df2_5['high'].isin([0.0,9.652254])]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Panel"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "平台get_price,如果是多只股票，则返回pandas.Panel对象。  \n",
    "可通过panel[列标,行标,股票代码]获取数据。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[[9.17058255e+00, 3.33288896e+00, 2.11073970e+00, 5.83124359e-01],\n",
       "        [7.14377380e+00, 4.35061753e+00, 4.83786329e+00, 1.33864196e+00],\n",
       "        [2.40518759e+00, 5.38936438e+00, 7.90854050e+00, 1.04793030e+00],\n",
       "        [2.74410552e+00, 3.93381745e+00, 2.18544107e-01, 5.68690265e+00],\n",
       "        [3.90191837e+00, 2.71524607e+00, 7.01980556e+00, 2.00076435e+00],\n",
       "        [7.91304217e+00, 7.27773302e+00, 1.72190591e+00, 5.15888726e-01],\n",
       "        [7.85200625e+00, 2.86564475e+00, 9.61629552e+00, 9.62642646e+00],\n",
       "        [6.09522587e+00, 9.48314485e+00, 5.13044105e+00, 5.82713123e+00],\n",
       "        [5.86401415e+00, 7.25242193e+00, 8.30539948e+00, 5.93246072e+00],\n",
       "        [5.26405281e-01, 7.58923892e+00, 2.78053014e+00, 2.79060412e+00]],\n",
       "\n",
       "       [[1.75562521e-01, 5.40826387e+00, 9.72818512e+00, 6.88943680e-03],\n",
       "        [9.01564571e+00, 1.13993243e+00, 6.96232577e+00, 9.58431881e+00],\n",
       "        [8.76032625e+00, 3.59015549e+00, 1.36210554e+00, 2.15452294e+00],\n",
       "        [6.46024079e-01, 3.90882376e+00, 8.02790283e-01, 1.32917216e+00],\n",
       "        [1.62073026e+00, 6.37910235e+00, 1.96176109e+00, 2.91636070e+00],\n",
       "        [9.96203445e+00, 8.53319589e+00, 8.90074321e+00, 1.44720248e+00],\n",
       "        [9.36570727e+00, 3.21630856e+00, 5.43426673e+00, 2.84604627e+00],\n",
       "        [4.36962995e+00, 4.83541970e+00, 4.68512119e+00, 2.46356518e+00],\n",
       "        [5.74778144e+00, 3.11250122e+00, 2.51489603e+00, 4.99328091e-01],\n",
       "        [2.93849928e+00, 3.63918704e-01, 6.07531699e+00, 1.10398462e+00]]])"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np \n",
    "\n",
    "dates = pd.date_range('20190601', periods=10)\n",
    "zreo_one_distributes_2 = np.random.rand(2,10,4)*10 # 2个数组10行4列\n",
    "zreo_one_distributes_2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\pcApp\\Anaconda3\\lib\\site-packages\\IPython\\core\\interactiveshell.py:2963: FutureWarning: \n",
      "Panel is deprecated and will be removed in a future version.\n",
      "The recommended way to represent these types of 3-dimensional data are with a MultiIndex on a DataFrame, via the Panel.to_frame() method\n",
      "Alternatively, you can use the xarray package http://xarray.pydata.org/en/stable/.\n",
      "Pandas provides a `.to_xarray()` method to help automate this conversion.\n",
      "\n",
      "  exec(code_obj, self.user_global_ns, self.user_ns)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<class 'pandas.core.panel.Panel'>\n",
       "Dimensions: 2 (items) x 10 (major_axis) x 4 (minor_axis)\n",
       "Items axis: 0 to 1\n",
       "Major_axis axis: 0 to 9\n",
       "Minor_axis axis: 0 to 3"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list = ['open','high','low','close']\n",
    "p3 = pd.Panel(zreo_one_distributes_2)\n",
    "p3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>9.170583</td>\n",
       "      <td>3.332889</td>\n",
       "      <td>2.110740</td>\n",
       "      <td>0.583124</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>7.143774</td>\n",
       "      <td>4.350618</td>\n",
       "      <td>4.837863</td>\n",
       "      <td>1.338642</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2.405188</td>\n",
       "      <td>5.389364</td>\n",
       "      <td>7.908540</td>\n",
       "      <td>1.047930</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2.744106</td>\n",
       "      <td>3.933817</td>\n",
       "      <td>0.218544</td>\n",
       "      <td>5.686903</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>3.901918</td>\n",
       "      <td>2.715246</td>\n",
       "      <td>7.019806</td>\n",
       "      <td>2.000764</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>7.913042</td>\n",
       "      <td>7.277733</td>\n",
       "      <td>1.721906</td>\n",
       "      <td>0.515889</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>7.852006</td>\n",
       "      <td>2.865645</td>\n",
       "      <td>9.616296</td>\n",
       "      <td>9.626426</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>6.095226</td>\n",
       "      <td>9.483145</td>\n",
       "      <td>5.130441</td>\n",
       "      <td>5.827131</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>5.864014</td>\n",
       "      <td>7.252422</td>\n",
       "      <td>8.305399</td>\n",
       "      <td>5.932461</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0.526405</td>\n",
       "      <td>7.589239</td>\n",
       "      <td>2.780530</td>\n",
       "      <td>2.790604</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3\n",
       "0  9.170583  3.332889  2.110740  0.583124\n",
       "1  7.143774  4.350618  4.837863  1.338642\n",
       "2  2.405188  5.389364  7.908540  1.047930\n",
       "3  2.744106  3.933817  0.218544  5.686903\n",
       "4  3.901918  2.715246  7.019806  2.000764\n",
       "5  7.913042  7.277733  1.721906  0.515889\n",
       "6  7.852006  2.865645  9.616296  9.626426\n",
       "7  6.095226  9.483145  5.130441  5.827131\n",
       "8  5.864014  7.252422  8.305399  5.932461\n",
       "9  0.526405  7.589239  2.780530  2.790604"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 展示第1层\n",
    "p3[0,:,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "      <th>2</th>\n",
       "      <th>3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.175563</td>\n",
       "      <td>5.408264</td>\n",
       "      <td>9.728185</td>\n",
       "      <td>0.006889</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>9.015646</td>\n",
       "      <td>1.139932</td>\n",
       "      <td>6.962326</td>\n",
       "      <td>9.584319</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>8.760326</td>\n",
       "      <td>3.590155</td>\n",
       "      <td>1.362106</td>\n",
       "      <td>2.154523</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.646024</td>\n",
       "      <td>3.908824</td>\n",
       "      <td>0.802790</td>\n",
       "      <td>1.329172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1.620730</td>\n",
       "      <td>6.379102</td>\n",
       "      <td>1.961761</td>\n",
       "      <td>2.916361</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>9.962034</td>\n",
       "      <td>8.533196</td>\n",
       "      <td>8.900743</td>\n",
       "      <td>1.447202</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>9.365707</td>\n",
       "      <td>3.216309</td>\n",
       "      <td>5.434267</td>\n",
       "      <td>2.846046</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>4.369630</td>\n",
       "      <td>4.835420</td>\n",
       "      <td>4.685121</td>\n",
       "      <td>2.463565</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>5.747781</td>\n",
       "      <td>3.112501</td>\n",
       "      <td>2.514896</td>\n",
       "      <td>0.499328</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2.938499</td>\n",
       "      <td>0.363919</td>\n",
       "      <td>6.075317</td>\n",
       "      <td>1.103985</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1         2         3\n",
       "0  0.175563  5.408264  9.728185  0.006889\n",
       "1  9.015646  1.139932  6.962326  9.584319\n",
       "2  8.760326  3.590155  1.362106  2.154523\n",
       "3  0.646024  3.908824  0.802790  1.329172\n",
       "4  1.620730  6.379102  1.961761  2.916361\n",
       "5  9.962034  8.533196  8.900743  1.447202\n",
       "6  9.365707  3.216309  5.434267  2.846046\n",
       "7  4.369630  4.835420  4.685121  2.463565\n",
       "8  5.747781  3.112501  2.514896  0.499328\n",
       "9  2.938499  0.363919  6.075317  1.103985"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取出第2层\n",
    "p3[1,:,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2.405188</td>\n",
       "      <td>8.760326</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5.389364</td>\n",
       "      <td>3.590155</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>7.908540</td>\n",
       "      <td>1.362106</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.047930</td>\n",
       "      <td>2.154523</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1\n",
       "0  2.405188  8.760326\n",
       "1  5.389364  3.590155\n",
       "2  7.908540  1.362106\n",
       "3  1.047930  2.154523"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取出两层叠放数据中，索引位置为3的数据\n",
    "p3[:,2,:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>0</th>\n",
       "      <th>1</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.583124</td>\n",
       "      <td>0.006889</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.338642</td>\n",
       "      <td>9.584319</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.047930</td>\n",
       "      <td>2.154523</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>5.686903</td>\n",
       "      <td>1.329172</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2.000764</td>\n",
       "      <td>2.916361</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.515889</td>\n",
       "      <td>1.447202</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>9.626426</td>\n",
       "      <td>2.846046</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>5.827131</td>\n",
       "      <td>2.463565</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>5.932461</td>\n",
       "      <td>0.499328</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2.790604</td>\n",
       "      <td>1.103985</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          0         1\n",
       "0  0.583124  0.006889\n",
       "1  1.338642  9.584319\n",
       "2  1.047930  2.154523\n",
       "3  5.686903  1.329172\n",
       "4  2.000764  2.916361\n",
       "5  0.515889  1.447202\n",
       "6  9.626426  2.846046\n",
       "7  5.827131  2.463565\n",
       "8  5.932461  0.499328\n",
       "9  2.790604  1.103985"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 取出两层中，索引位置为3的数据\n",
    "p3[:,:,3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Panel的操作与DataFrame的操作基本相同。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {
    "height": "calc(100% - 180px)",
    "left": "10px",
    "top": "150px",
    "width": "336px"
   },
   "toc_section_display": true,
   "toc_window_display": true
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
